#ifndef __SURVEILLANCE__
#define __SURVEILLANCE__

#include <QObject>
#include <QThread>
#include <QProcess>
#include <QDateTime>

class Coordinator;
class QTimer;
class QProcess;

class Surveillance_Worker : public QObject
{

	Q_OBJECT

public:

	Surveillance_Worker(QObject *parent = nullptr);
	~Surveillance_Worker();

	bool online() { return m_camera1_online | m_camera2_online; };

signals:


public slots:

	void start();
	void stop();

	void start_video_record();
	void stop_video_record();

private slots:

	void camera_check();

	void errorOccurred(QProcess::ProcessError error);
	void finished(int exitCode, QProcess::ExitStatus exitStatus);
	void readyReadStandardError();
	void readyReadStandardOutput();
	void started();
	void stateChanged(QProcess::ProcessState newState);

private:

	void freeSpace();

private:

	bool m_camera1_online;
	bool m_camera2_online;

	QString m_device1_name;
	QString m_device2_name;
	QString m_video_path;
	QDateTime m_start_time, m_stop_time;

	QProcess *m_process;

	QTimer *m_check_timer;

};

class SurveillanceController : public QObject
{
	Q_OBJECT

public:

    SurveillanceController(QObject *parent = nullptr);
    ~SurveillanceController();

    Surveillance_Worker *getWorker() {
        return m_worker;
    }

signals:

	void start();
	void stop();

private:

	QThread m_worker_thread;
	Surveillance_Worker *m_worker;

    Coordinator *m_coordinator;
};

#endif
